<?php

namespace common\models\cms;

use Yii;
use common\helpers\Url;

/**
 * This is the model class for table "{{%cms_special_nav}}".
 *
 * @property int $id
 * @property int $special_id 专题ID
 * @property string|null $name
 * @property string $title 名称
 * @property string|null $thumb 缩略图
 * @property string|null $description 描述
 * @property int $reserved 系统保留
 * @property int $map_id
 * @property string|null $map_data
 * @property int $listorder 显示排序
 * @property int $status
 * @property int $created_at
 * @property int|null $updated_at
 * @property int $deleted_at
 */
class CmsSpecialNav extends \common\db\ActiveRecord {

    use \common\traits\WeblinkTrait;

    /**
     * 状态
     */
    const STATUS_ACTIVE = 10;
    const STATUS_DEFAULT = 0;

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%cms_special_nav}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['special_id', 'reserved', 'map_id', 'listorder', 'status', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
            [['title'], 'required'],
            [['name'], 'string', 'max' => 50],
            [['title'], 'string', 'max' => 80],
            [['thumb', 'description', 'map_data'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'special_id' => '专题ID',
            'name' => '标识名',
            'title' => '名称',
            'thumb' => '缩略图',
            'description' => '描述',
            'reserved' => '系统保留',
            'map_id' => 'Map ID',
            'map_data' => 'Map Data',
            'listorder' => '显示排序',
            'status' => '启用状态',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
            'deleted_at' => 'Deleted At',
        ];
    }

    /**
     * 关联专题信息
     * @return \common\db\ActiveQuery the relational query object.
     */
    public function getSpecial() {
        return $this->hasOne(CmsSpecial::class, ['id' => 'special_id']);
    }

    /**
     * 获取导航跳转地址标题
     * @return string
     */
    public function getMapTitle() {
        return $this->title;
    }

    /**
     * 获取导航缩略图
     * @return string
     */
    public function getThumbUrl() {
        return Url::attach($this->thumb);
    }

    /**
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'id',
            'name',
            'title',
            'thumb' => 'thumbUrl',
            'description',
            'weblink',
        ];
    }

}
